package tests;

import java.util.logging.Level;
import controlisolation.lifecyclefsm.LifeCycleFSMController;
import controlisolation.lifecyclefsm.NoWork;
import controlisolation.lifecyclefsm.stateexecutor.StateWork;

public class AbStateMachineController extends LifeCycleFSMController {
	private NoWork _noWork=new NoWork();

	@Override
	public void controlCycle() throws Exception {
		StateWork work;
		work=_lfsm.getCurrentStateWork();
		if (work==null) {
			if (!_lfsm.isInitial(_lfsm.getCurrentState())){
				_logger.log(Level.INFO,"No work defined for state: using default!");
			}
		work=_noWork;
		}
		if (_lfsm.getCurrentState().getId().equals("initState")){
		/* Control Code for state initState */
		/* Possible transitions to take at this point are: 
		start_evt will take to theAState
		*/
		if(work.suscessful()){
		_lfsm.fireFSMEvent(decissionControlFrom_initState(work));
		} else /* work produced fatal errors or exceptions */ {
			errorControlFor_initState(work);
		}
		return; } 
		/* State Control Code Ended */

		if (_lfsm.getCurrentState().getId().equals("theAState")){
		/* Control Code for state theAState */
		/* Possible transitions to take at this point are: 
		a_evt will take to theBState
		*/
		if(work.suscessful()){
		_lfsm.fireFSMEvent(decissionControlFrom_theAState(work));
		} else /* work produced fatal errors or exceptions */ {
			errorControlFor_theAState(work);
		}
		return; } 
		/* State Control Code Ended */

		if (_lfsm.getCurrentState().getId().equals("theBState")){
		/* Control Code for state theBState */
		/* Possible transitions to take at this point are: 
		b_evt will take to theAState
		*/
		if(work.suscessful()){
		_lfsm.fireFSMEvent(decissionControlFrom_theBState(work));
		} else /* work produced fatal errors or exceptions */ {
			errorControlFor_theBState(work);
		}
		return; } 
		/* State Control Code Ended */

	throw new Exception("Unexpected State");
	} //end of control method

	private String decissionControlFrom_initState(StateWork work) {
		/* Possibe target states from this state: 
			| start_evt | 
			 will result in jumping to state: theAState
			Do event selection logic here */
	return "start_evt";
	}
	private String decissionControlFrom_theAState(StateWork work) {
		/* Possibe target states from this state: 
			| a_evt | 
			 will result in jumping to state: theBState
			Do event selection logic here */
	return "a_evt";
	}
	private String decissionControlFrom_theBState(StateWork work) {
		/* Possibe target states from this state: 
			| b_evt | 
			 will result in jumping to state: theAState
			Do event selection logic here */
	return "b_evt";
	}
	private void errorControlFor_initState(StateWork work) {
		unifiedErrorControl(work);
	}
	private void errorControlFor_theAState(StateWork work) {
		unifiedErrorControl(work);
	}
	private void errorControlFor_theBState(StateWork work) {
		unifiedErrorControl(work);
	}
} //end of class 
